// 文章相关的操作, 全封装在这里
import http from '@/utils/request.js'

/**
 * 获取某个频道下的文章列表
 * @param {*} channelId 频道id
 * @param {*} timestamp 时间戳
 */
export const reqGetArticles = (channelId, timestamp) => {
  return http({
    method: 'get',
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp
    }
  })
}
/**
 * 不喜欢文章(不感兴趣)、
 * @param {*} articleId 文章 id
 */
export const reqDisLikeArticle = (articleId) => http({
  method: 'post',
  url: '/v1_0/article/dislikes',
  data: { target: articleId }
})

// 举报文章api
export const reqReportArticle = (target, type, remark = '') => {
  return http({
    method: 'post',
    url: '/v1_0/article/reports',
    // post携带参数  data
    data: {
      target, // 不喜欢的文章的id
      type, // 举报类型  0-其他问题，1-标题夸张，2-低俗色情，3-错别字多，4-旧闻重复，5-广告软文，6-内容不实，7-涉嫌违法犯罪，8-侵权'
      remark // 举报的附加说明
    }
  })
}

/**
 * 根据文章编号来获取文章详情
 * @param {*} id 文章编号
 */
export const reqGetArticleDetail = id => http({
  url: '/v1_0/articles/' + id
})

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const reqDeleteLike = id => {
  return http({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}

/**
 * 添加点赞
 * @param {*} id 文章编号
 */
export const reqAddLike = id => {
  return http({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const reqDeleteDisLike = id => {
  return http({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
 * 添加不喜欢
 * @param {*} id 文章编号
 */
export const reqAddDisLike = id => {
  return http({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}
